from selenium.webdriver.common.by import By
from common.Utils import BlogDriver
from tests.BlogLogin import BlogLoginDriver
from time import sleep

# 测试简墨博客详情页
class BlogDetail:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_detail.html?blogId=158477"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)
        self.driver.maximize_window()
    # 登录状态下的简墨博客详情的测试用例
    def DetailByLogin(self):
        # 查找简墨博客文章详情元素：标题、发表时间、内容
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.title")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.date")
        self.driver.find_element(By.CSS_SELECTOR, "#detail")
        # 查找简墨博客个人信息：头像、昵称、文章、文章数量、分类、分类数量
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > img")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(5) > span:nth-child(2)")
        # 屏幕截图记录
        BlogDriver.getScreeShot()
        print("ListByLogin:>"+self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3").text)
        print("ListByLogin:>"+self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.title").text)
        print("ListByLogin:>"+self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.operating > button:nth-child(1)").text)
    # 未登录状态下的简墨博客详情的测试用例
    def DetailByNotLogin(self):
        # 会自动跳转回简墨登录页
        sleep(0.5)
        current_url = self.driver.current_url
        assert current_url != self.url
        print("DetailByNotLogin-before_url："+self.url)
        print("DetailByNotLogin-after_url："+current_url)
        # 屏幕截图记录
        BlogDriver.getScreeShot()

BlogDetailDriver = BlogDetail()
# BlogDetailDriver.DetailByNotLogin()
# BlogLoginDriver.LoginSucTest()
# BlogLoginDriver.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(2) > a").click()
# BlogDetailDriver.DetailByLogin()
# BlogDriver.driverQuit()